package com.lanou.dllo.soccernews.database;

import com.lanou.dllo.soccernews.application.BaseApplication;
import com.lanou.dllo.soccernews.bean.greendao.ArticlesEntity;
import com.lanou.dllo.soccernews.bean.greendao.DaoSession;
import com.lanou.dllo.soccernews.bean.greendao.DeepBeanArticlesEntity;

import java.util.List;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * Created by dllo on 15/11/2.
 */
public class DeepHelp {

    private static DeepHelp deepHelp;
    private static DaoSession daoSession;

    private DeepHelp() {

    }

    public static DeepHelp getInstance() {
        if (deepHelp == null) {
            deepHelp = new DeepHelp();
            daoSession = BaseApplication.getDaoSession();
        }

        return deepHelp;
    }

    public List<DeepBeanArticlesEntity> getArticlesEntity() {
        QueryBuilder<DeepBeanArticlesEntity> qb = daoSession.getDeepBeanArticlesEntityDao().queryBuilder();
        return qb.list();
    }

    public void addArticlesEntity(List<DeepBeanArticlesEntity> articles) {
        daoSession.getDeepBeanArticlesEntityDao().insertInTx(articles);
    }
}
